<?php
namespace app\h5api\controller;

use app\common\model\ApplyReg;
use app\common\model\Shops;
use app\h5api\validate\Register as RegisterValidate;
use Upload;

class Register extends Base
{

    /**
     * @route('h5/register')
     * 商铺注册
     */
    public function register()
    {
        $phone = input('phone');
        $data = input();
		$data['user_id'] = $this->_userid;
		$data['telphone'] = $phone;

		$validate = new RegisterValidate();
		if(!$validate->scene('register')->check($data)){
			$this->result([],-1,$validate->getError());
		}

		$shop = Shops::where('shop_phone',$phone)->find();
		if($shop){
			$this->result([],-1,'该手机号注册商铺已存在');
		}
        $applymodel = new ApplyReg();
		$data['imagesurl'] = "/uploads/approve/20230507/d8e096a79eca8106cf15e86d5cfd8f45.png";
        $result = $applymodel->edit($data);
        if(!$result){
            $this->result([],-1,$applymodel->getError());
        }
        $this->result([],1,'申请成功');
    }

    /**
     * @route('h5/uploadshopimage','post')
     * 注册商铺上传图片
     */
    public function uploadshopimage()
    {
        $type = input('post.type_name');
        switch($type){
            case 'applyreg':
                // 注册
                $path = 'approve';
                break;
            case 'comment':
                // 评论
                $path = 'comment';
                break;
            case 'after':
                // 售后
                $path = 'after';
                break;
            default:
                $this->result('',-1,'图片类型错误');
        }
        $res = Upload::FileUpload('image',$path,1024*1024*5,'jpg,png,jpeg');
        if(!$res['data']){
            $this->result([],-1,$res['msg']);
        }
        $this->result($res['data'],1,'操作成功');
    }
}
